﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using ContractManagementSystem.BusinessLogic;
using ContractManagementSystem.Entity;

namespace ContractManagementSystem
{
    public partial class PageReportLineManager : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SearchLineManager();
                ViewLineManagerPanel.Visible = true;
            }
        }

        public void SearchLineManager()
        {
            if (!string.IsNullOrEmpty(FullNameTextBoxSearch.Text))
            {
                ViewAllLineManagerListView.DataSource = LineManagerBusiness.SearchFullName(FullNameTextBoxSearch.Text);
                ViewAllLineManagerListView.DataBind();
                Session["ReportClient"] = LineManagerBusiness.SearchFullName(FullNameTextBoxSearch.Text);
            }
            else
            {
                ViewAllLineManagerListView.DataSource = LineManagerBusiness.FetchAll(ActiveDropDownList.SelectedIndex);
                ViewAllLineManagerListView.DataBind();
                Session["ReportClient"] = LineManagerBusiness.FetchAll(ActiveDropDownList.SelectedIndex);
            }

        }

        protected void FullNameTextBoxTextChanged(object sender, EventArgs e)
        {
            SearchLineManager();
        }

        protected void DataPager1_OnPreRender(object sender, EventArgs e)
        {
            SearchLineManager();
        }

        protected void ActiveDropDownList_SelectedIndexChanged(object sender, EventArgs e)
        {
            SearchLineManager();
        }

        protected void DeleteButton1_OnCommand(object sender, CommandEventArgs e)
        {
            var lineManagerEntity = new LineManagerEntity { LineManagerId = new Guid(e.CommandArgument.ToString()) };
            LineManagerBusiness.Delete(lineManagerEntity);
            SearchLineManager();
        }

        protected void ReportButton_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/ReportLineManager.aspx");
        }
    }
}
